﻿<?php 

require '../../frame/base.php';
include("../../tool/UpFileTool.class.php");
$tag = !empty($_REQUEST['tag'])?$_REQUEST['tag']:null;
$_REQUEST['page'] = !empty($_REQUEST['page'])?$_REQUEST['page']:'';
$_REQUEST['pagesize'] = !empty($_REQUEST['pagesize'])?$_REQUEST['pagesize']:'';
echo json_encode(['!'=>$_REQUEST]);die;

// 分页
if($_REQUEST['page']!="" && $_REQUEST['pagesize']!=""){
	$de=$_REQUEST['page']*$_REQUEST['pagesize'];
	$size=$_REQUEST['pagesize'];
}else{
	$de=0;
	$size=20;
}
// 分页 end
//shopid&comments&comments_pic&is_nobody&describe_comments&wuliu_service&taidu_service

$comments = !empty($_REQUEST['comments']) ? $_REQUEST['comments'] : '';
$is_nobody = ( $_REQUEST['is_nobody']=='true' ) ? true : false;
$describe_comments = !empty($_REQUEST['describe_comments']) ? $_REQUEST['describe_comments'] : '5';
$shopid = !empty($_REQUEST['shopid']) ? $_REQUEST['shopid'] : '';
$wuliu_service = !empty($_REQUEST['wuliu_service']) ? $_REQUEST['wuliu_service'] : '5';
$taidu_service = !empty($_REQUEST['taidu_service']) ? $_REQUEST['taidu_service'] : '5';

	if ($_FILES['comments_pic']['tmp_name']!='') {
		$UpFileTool=new UpFileTool('upfile');
		$UpFileTool->sumbImage($w=300, $h=300);
		$UpFileTool->upFile();
		$comments_pic = $UpFileTool->sumbImage;
		$srcimages = $UpFileTool->srcImage;
		
	}else{
		$images='';
	}


$data1 = [
	'comments'=>$comments,
	'comments_pic'=>$comments_pic,
	'is_nobody'=>$is_nobody,
	'describe_goods'=>$describe_comments,
	'wuliu_service'=>$wuliu_service,
	'taidu_service'=>$taidu_service,
	'comment_state'=>'1',
	'state'=>'5',
];

//fetchSql(true)->find();

//店铺评分
$_wuliu=$Db->table('goodsorders')->field("AVG(wuliu_service)")->where('shopid',$shopid)->find();
$_wuliu=round($_wuliu['AVG(wuliu_service)']);

$_taidu=$Db->table('goodsorders')->field("AVG(taidu_service)")->where('shopid',$shopid)->find();
$_taidu=round($_taidu['AVG(taidu_service)']);

$data2 = [
	'wuliu_service'=>$_wuliu,
	'taidu_service'=>$_taidu,
];

if($tag=="report"){

	if( $Db->table('goodsorders')->where('ordersid',$_REQUEST['ordersid'])->where('userid',$_REQUEST['userid'])->update($data1) ){
		$Db->table('shop')->where('shopid',$shopid)->update($data2);
		echo json_encode(['code'=>200,'msg'=>'成功']);
	}

}else if($tag=="query"){
	$resultData = $Db->table('goodsorders')->field('ordersid,comment_state')->where(['ordersid'=>$_REQUEST['ordersid'], 'userid'=>$_REQUEST['userid'] ])->select();
	echo json_encode(['code'=>200,'msg'=>'成功','data'=>$resultData]);
}else if($tag==""){

}else{

}
